<include file="Public:head" />
<link href="__APP__/Application/{$Think.MODULE_NAME}/Public/css/order.css" rel="stylesheet" type="text/css" />
<script src="__PUBLIC__/js/jquery/placeholder.js" type="text/javascript"></script>
<script  type="text/javascript">
    $(function() {
        $("#leave_message_box").placeholder();
        if ($('#saveTip').length == 1) {
            setTimeout("goHide('#saveTip')", 3000)
        }
        $('#leave_message').children("a").focus(function() {
            var val = $(this).children("span").text();
            var message = $('#leave_message_box').val();
            if (message.indexOf(val) < 0) {
                $('#leave_message_box').val(message + " " + val);
            }
        })
        var len = $('div.order_p_address').length;
        if ($('div.order_p_address').length > 0) {
            if ($(".order_p").length == 0) {
                $('.order_p_address:first').addClass("order_p").removeClass("order_p2");
            }
            $('div.order_p_address').hover(function() {
                $(this).children("a.delete").show();
                $(this).children("a.edit").show();
                $(this).children("a.edit2").css({"display": "inline-block"});
            }, function() {
                $(this).children("a.delete").hide();
                $(this).children("a.edit").hide();
                $(this).children("a.edit2").hide();
            })
        }
    })
    function showMessageBox() {
        $('#leave_message').show();
    }

    function setTimes(obj, t) {
        $('#input_time').text(obj.text());
        $('#time_list').hide();
        $('.ui_dropdown_toggle').show();
        $('#input_time').attr("data-time", t);
    }
    function editAddr(obj, id) {
        var addr = obj.prevAll('.u_addr').text();
        var phone = obj.prevAll('.u_phone').text();
        var truename = obj.prevAll('.u_truename').text();
        var phone2 = obj.prevAll('.u_phone2').text();
        $.post("{:U('Box/addAddr')}", {
            id: id,
            phone: phone,
            phone2: phone2,
            addr: addr,
            truename: truename
        }, function(data) {
            $('#mainbox').html(data);
            showbgbox('#browsebox', 0, 0);
        })

    }
    function addAddr() {
        $.post("{:U('Box/addAddr')}", {
        }, function(data) {
            $('#mainbox').html(data);
            showbgbox('#browsebox', 0, 0);
        })
    }
    function delAddr(obj, id) {
        $.post("{:U('Box/delAddr')}", {
            id: id
        }, function(data) {
            obj.parent(".order_p_address").remove();
            var div = "<p class='order_p2 order_p_address' onclick='addAddr()'>\n\
送餐地址：<span class='address_phone'>&nbsp;<em>请填写地址</em></span>\n\
<a class='change_address' onclick='addAddr()' href='javascript:;'> [填写]</a></p>";

            if ($("div.order_p_address").length == 0) {
                $('.order_p_time').before(div);
            }
        })
    }
    function addOrder() {
        var sendtime = $('#input_time').attr("data-time");
        var message = $('#leave_message_box').val();
        if ($("div.order_p_address").length == 0) {
            showTip('系统提示', "请选择送餐地址！", '0');
            return false;
        }
        
        var area_id = $(".order_p").attr("data-id");
        $.post("{:U('Order/add')}", {
            area_id: area_id,
            message: message,
            sendtime: sendtime
        }, function(data) {
            if(data>0){
                var url = "__APP__/Order/success/id/" + data + ".html";
                goUrl(url);
            }else{
               showTip('系统提示', data, '0');
            }
        })
    }
    function setAddr(obj, id) {
        $(".order_p_address").removeClass("order_p").addClass("order_p2");
        obj.removeClass("order_p2").addClass("order_p");
    }
</script>

<div id="wrap" style="width: 750px;">
    <div id="school">{$type=0|getAreaName}
        <a href="__APP__/?type=clean">[切换位置]</a>
        <span>/</span>
        <em>美食篮</em>
    </div>
    <div id="order" class="shadow">
        
        <empty name='carts'>
            
            <div id="empty">
                <h2>您的美食篮还是空的，赶紧行动吧！您可以：</h2>
                <ul style='margin-top: 12px'>
                    <li>
                        马上去
                        <a style="color: #55ACDC" href="{:U('Area/lists',array('id'=>$sessionAreaId))}">购买</a>
                    </li>
                    <li  style='padding-top: 4px'>
                        看看
                        <a style="color: #55ACDC" href="{:U('Member/order')}">已买到的美食</a>
                    </li>
                </ul>
            </div>
            <else/>
            <div class="order_top clearfix">
                <ul class="clearfix buy_item fr">
                    <li>1.选择美食</li>
                    <li>3.完成订单</li>
                    <li>2.确认订单</li>
                    <li class="buy_item_last">&nbsp;</li>
                </ul>
                <img src='{$shop.logo|getShopLogo=###,43}' class="fl" />
                <p><a>{$shop.name}</a></p>
                <p>起送价：{$shop.startprice}元起送！</p>
            </div>

            <table cellpadding="0" cellspacing="0">
                <thead>
                    <tr>
                        <td width="150px">美食筐</td>
                        <td class="col2">单价</td>
                        <td class="col3">数量</td>
                        <td class="col4">总计</td>
                    </tr>
                </thead>
                <tbody>
                <foreach name="cartsArr[0]['sub']" item="row">
                    <tr>
                        <td>{$row.name}</td>
                        <td>￥{$row['price']-$row['discount']|getOneDot=###}</td>
                        <td>{$row.num}</td>
                        <td >￥{$row['price']-$row['discount']|getcartTotal=###,$row['num']}</td>
                    </tr>
                </foreach>

                <tr>
                    <td class="leave_message">
                        <input type="text" placeholder="给餐厅留言" id="leave_message_box" autocomplete="off" onclick="showMessageBox()" onblur="hideBlur('#leave_message')" />
                        <div class="leave_message_list clearfix order_shadow" id="leave_message">
                            <a href="javascript:;">
                                <span>不吃辣</span>
                                <b class="leave_message_blank_b">◆</b>
                                <b class="leave_message_color_b">◆</b>
                            </a>
                            <a href="javascript:;"><span>辣一点</span></a> <a href="javascript:;"><span>多加米</span></a>
                            <a href="javascript:;"><span>么零钱</span></a> <a href="javascript:;" class="last_child">
                                <span>不要葱姜蒜</span></a>
                        </div>
                    </td>
                    <td colspan="3">
                        <p class="order_total">
                          共<em>{$cart_num}</em>份美食&nbsp;&nbsp;<if condition="$cartsArr[0]['sendprice'] gt 0">配送费：¥{$cartsArr[0]['sendprice']}</if> &nbsp;&nbsp;总额：<em>¥
                                <if condition="$cartsArr[0]['sales_cut'] gt 0 && $total_price gt $cartsArr[0]['sales_full']"> 
                                    {$total_price}-{$cartsArr[0]['sales_cut']|getOneDot}={$total_price-$cartsArr[0]['sales_cut']|getOneDot}
                                    <else/>
                                    {$total_price}
                                </if>
                            </em>
                        </p>
                        <!--是否支持满减-->
                <if condition="$cartsArr[0]['sales_cut'] gt 0 && $total_price gt $cartsArr[0]['sales_full']">
                    <div id="saveTip" class="order_shadow">
                        <p>
                            此餐厅参加“<em>满{$cartsArr[0]['sales_full']}元减{$cartsArr[0]['sales_cut']}元活动</em>”您的订单已满{$cartsArr[0]['sales_full']}元，自动减去{$cartsArr[0]['sales_cut']}元，恭喜您啦!</p>
                        <span onclick="$('#saveTip').hide()">[我知道了]</span>
                        <b class="saveTip_blank_b">◆</b> <b class="saveTip_color_b">◆</b>
                    </div>
                </if>

                </td>
                </tr>
                </tbody>
            </table>

            <a href="{:U('Member/addr')}" class="addAddrBtn" style="margin-left: 10px;">管理收货地址</a>
            <a id="addAddrBtn" class="addAddrBtn" onclick="addAddr()">添加新地址</a>
            <div class="clear"></div>
            <empty name="addrs">
                <p class="order_p2 order_p_address" onclick="addAddr()" >
                    送餐地址：
                    <span class="address_phone">
                        <em>请填写地址</em>
                    </span>
                    <a class="change_address" href="javascript:;" onclick="addAddr()"> [填写]</a>
                </p>
                <else/>
                <foreach name="addrs" item="row">
                    <div onclick="setAddr($(this), '{$row.id}')" <if condition="$row.is_default eq 1">class="order_p order_p_address"<else/>class="order_p2 order_p_address"</if> id="addr_{$row.id}" data-id="{$row.id}">
                        <span class="u_truename">{$row.truename}</span>
                        <span class="u_phone">{$row.phone}</span>

                        <span class="u_phone2">{$row.phone2}</span>
                        <span class="u_addr">{$row.addr}</span>
                        <a class="delete" style="display: none" onclick="delAddr($(this), '{$row.id}')" href="javascript:;">×</a>
                        <a class="edit" style="display: none" onclick="editAddr($(this), '{$row.id}')" href="javascript:;">修改</a>
                    </div>
                </foreach>
            </empty>
            <!--送餐时间-->
            <div class="order_p3 order_p_time">
                送出时间：
                <div id="time_dropdown" class="ui_dropdown time">
                    <a class="ui_dropdown_toggle" onclick="$('#time_list').show();
                            $('.ui_dropdown_toggle').hide();" tabindex="1" onblur="hideBlur('#time_list');
                                    $('.ui_dropdown_toggle').show()">
                        <span id="input_time" data-time="0">立即送出</span> 
                        <i class="icon_caret"><b></b><b></b></i>
                    </a>
                    <ul id="time_list" class="ui_dropdown_menu">
                        <li onclick="setTimes($(this), '0')">立即送出</li>
                        <foreach name="times" item="row">
                            <li onclick="setTimes($(this), '{$row.t2}')">{$row.t}</li>
                        </foreach>

                    </ul>
                </div>
            </div>
            <input type="button" id="sendOrder" value="确认下单" onclick="addOrder()" />
        </empty>
    </div>
</div>

<include file="Public:foot" />



